package com.itsu.commons.utils;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import com.itsu.interfaces.entity.Publish;
import com.itsu.interfaces.entity.RecommendUser;
import com.itsu.interfaces.entity.UserInfoEntity;
import com.itsu.pojo.vo.QuanZiVo;
import com.itsu.pojo.vo.TodayBest;

import java.util.Date;

public class VoUtil {

    public static TodayBest init(UserInfoEntity userInfo, RecommendUser recommendUser) {
        if (ObjectUtil.isNull(userInfo)){
            return null;
        }
        TodayBest vo = new TodayBest();
        vo.setId(userInfo.getUserId());
        vo.setAvatar(userInfo.getLogo());
        vo.setNickname(userInfo.getNickName());
        vo.setGender(userInfo.getSex() == 1 ? "woman" : "man");
        vo.setAge(userInfo.getAge());
        vo.setFateValue(recommendUser.getScore().longValue());
        if (userInfo.getTags() != null) {
            vo.setTags(userInfo.getTags().split(","));
        }
        return vo;
    }

    public static QuanZiVo Quanzi(UserInfoEntity userInfo, Publish publish) {
        if (ObjectUtil.isNull(userInfo)){
            return null;
        }
        QuanZiVo vo = new QuanZiVo();
        vo.setId(publish.getId().toHexString());
        vo.setUserId(publish.getUserId());
        vo.setAvatar(userInfo.getLogo());
        vo.setNickname(userInfo.getNickName());
        vo.setGender(userInfo.getSex() == 1 ? "woman" : "man");
        vo.setAge(userInfo.getAge());
        if (userInfo.getTags() != null) {
            vo.setTags(userInfo.getTags().split(","));
        }
        vo.setTextContent(publish.getText());
        vo.setImageContent(ArrayUtil.toArray(publish.getMedias(), String.class));
        vo.setCreateDate(RelativeDateFormat.format(new Date(publish.getCreated())));
        // 评论相关
        // 先给一些默认值 等到 后台讲完评论
        vo.setLikeCount(0);
        vo.setCommentCount(0);
        vo.setLoveCount(0);
        vo.setHasLiked(0);
        vo.setHasLoved(0);
        // 写死距离
        vo.setDistance("1.2公里");
        
        return vo;
    }
}
